<?php
	defined('BASEPATH') OR exit('No direct script access allowed');
	/**
	* 
	*/
	class Email extends CI_Controller{
		
		function __construct(){
			parent::__construct();
			$this->sendTo = '154063438@qq.com';
			$this->load->library('smail');
		}

		// 联系我们邮件
		function contact(){
			$name =	$this->input->get('name');
			$telphone = $this->input->get('telphone');
			$address = $this->input->get('address');
			$message = $this->input->get('message');
			if($name == '' || $telphone ==''){
				echo json_encode(array('success' => '0'));
				eixt;
			}
			$data = array(
				'name' => $name,
				'telphone' => $telphone,
				'address' => $address,
				'body' => $message
			);
			$bol = $this->smail->send(array(
				'to' => $this->sendTo,
				'subject' => $data['name'] . ' 森源之家客户联系',
				'body' => $this->load->view('templates/email_contact',$data,true)
			));

			echo json_encode(array('success' => $bol ? 1 : 0));
		}
		// 订单邮件
		function order(){

		}
		// 加盟邮件
		function join(){
			$data = array(
				'name' => $this->input->get('name'),
				'phone'=> $this->input->get('phone'),
				'email' => $this->input->get('email'),
				'address' => $this->input->get('address'),
				'address_complate' => $this->input->get('address_complate'),
				'complate' => $this->input->get('complate'),
				'point' =>  $this->input->get('point'),
			);
			if($data['name'] == '' || $data['phone'] ==''){
				echo json_encode(array('success' => '0', 'message' => '联系人和联系方式不能为空'));
				eixt;
			}

			$bol = $this->smail->send(array(
				'to' => $this->sendTo,
				'subject' => $data['name'] . '-森源加盟申请',
				'body' =>  $this->load->view('templates/email_join',$data,true)
			));

			echo json_encode(array('success' => $bol ? 1 : 0));
		}
	}